package com.xmotor.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class SysResult implements Serializable {

    private static final long serialVersionUID = 2080943344863436345L;

    private Integer code;
    private String msg;
    private Object data;
    private long timestamp;

    private SysResult(Integer code, String msg, Object data, long timestamp) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.timestamp = timestamp;
    }

    public static SysResult ok(Object data) {
        return new SysResult(200, "success", data, System.currentTimeMillis());
    }

    public static SysResult ok() {
        return ok(null);
    }

    public static SysResult fail(Integer code, String msg) {
        return new SysResult(code, msg, null, System.currentTimeMillis());
    }

    public static SysResult fail(String msg) {
        return fail(201, msg);
    }

    public static SysResult fail() {
        return fail(201, "fail");
    }

    public static SysResult fail(Throwable e) {
        return fail(e.getMessage());
    }
}
